import QtQuick 2.0

Item {
    id: root
    anchors.fill: parent
    opacity: 0

    signal readyToGo

    property bool splashIsReady: false
    property bool appIsReady: false
    property bool ready: appIsReady && splashIsReady
    onReadyChanged: {
        if (ready)
            readyToGo()
    }
    function appReady() {
        appIsReady = true
    }

    function errorInLoadingApp() {
        Qt.quit()
    }
    Column {
        anchors.centerIn: parent
        //width: parent.width
        //height: parent.height * 1 / 2
        Image {
            //anchors.centerIn: parent
            width: 150
            height: 150
            source: "qrc:/img/res/logo.png"
        }
        spacing: 15
        Text {
            anchors.horizontalCenter: parent.horizontalCenter
            id: element
            text: qsTr("WeFuck")
            color: "black"
            font.bold: true
            font.pointSize: 24
            font.family: "Courier"
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
        }
    }

    NumberAnimation {
        id: opAnimation
        target: root
        property: "opacity"
        duration: 200
        to: 0
    }

    NumberAnimation {
        id: openAnimation
        target: root
        property: "opacity"
        duration: 200
        to: 1
    }

    Timer {
        id: splashTimer
        interval: 1000
        onTriggered: {
            changeTimer.start()
            opAnimation.start()

            console.log("splashTimer timeout")
        }
    }

    Timer {
        id: changeTimer
        interval: 1000
        onTriggered: {
            console.log("changeTimer timeout")
            splashIsReady = true
        }
    }

    Component.onCompleted: {
        appReady()
        openAnimation.start()
        splashTimer.start()
    }
}
